# +-----------------------------------------------+
# | <TAG> Engine v0.20(Text Adventure Game Engine)|
# | Default Trigger Functions                     |
# | filename: triggers.py                         |
# | Created by KKSNetwork - http://thekks.net     |
# | Status: In Development - Pre-Alpha            |
# | Website: http://tagengine.sourceforge.net     |
# +-----------------------------------------------+
# |                    Credits                    |
# | Design: KKSNetwork                            |
# | Coding: Ultimatebuster                        |
# |         b-h                                   |
# | Beta Testers:                                 |
# | Feedback:                                     |
# | Contributors:                                 |
# +-----------------------------------------------+
# License information is available in the LICENSE.txt file


from types import *
from tagengine.commons import *
import logging
logger = logging.getLogger("triggers")

def dummyTrigger(args=None):
    return 0

##### ITEM TRIGGERS #####

def defaultOpen(args):
    item = args["item"]
    indirectObj = args["iobj"]
 
    if type(item.openable) == ListType or type(item.openable) == TupleType:
        if not indirectObj:
            output("It's locked.")
            return 0
            
        if indirectObj in item.openable:
            item.openable = 2
            output("You have opened %s." % item.name)
            if type(item.inventory) == ListType:
                print args["game"].expressItemsInSentence(item.inventory)
                
            return 1
        else:
            output("Can't open with that!")
            return 0
                             
    if item.openable == 1:
        item.openable = 2
        output("You have opened %s." % item.name)
        return 1
    elif item.openable == 2:
        item.openable = 1
        output("You have closed %s." % item.name)
        return 1

    
    return 0
        
def defaultDestroy(args):
    item = args["item"]
    weapon = args["weapon"]
    
    if item.destructible == True:
        item.location.inventory.remove(item)
        item.location = None
        output("You have destroyed %s." % item.name)
        return 1

    if type(item.destructible) == ListType:
        if weapon in item.destructible:
            item.location.inventory.remove(item)
            item.location = None
            output("You have destroyed %s." % item.name)
            return 1
    return 0

def defaultMove(args):   
    output("You moved %s, but nothing happened." % args["item"])
    return 1

def defaultTake(args):
    item = args["item"]
    returncode = item.sameRoomAsPlayer(True)
    if returncode:
        if returncode.type == Constants.CHARACTER_TYPE:
            if returncode.hostile:
                output("%s is hostile to you. You can't take the %s from " % (returncode.name, item.name, Maps.GenderToObjectivePronoun[returncode.gender]))
                return 0
            else:
                if not returncode.friendly:
                    returncode.hostile = 1
        item.game.player.inventory.append(item)
        item.location.inventory.remove(item)
        item.location = item.game.player
        output("You have taken the %s." % item.name)
        if returncode.hostile:
            output("%s is now hostile to you." % returncode.name)
        return 1
    elif item.inPlayerInventory():
        output("You already have the %s." % item.name)
        return 0
    return 0
    
def defaultWear(args):
    if args["item"].inPlayerInventory():
        print "You wore it."
    return 0
    
def defaultRead(args):
    item = args["item"]
    if type(item.readable) == StringType or type(item.readable) == UnicodeType:
        output(item.readable)
        return 1
    else:
        output("There's nothing written on the %s" % item.name)
        return 0
    
    return 0
        
def defaultLight(args):
    item = args["item"]
    indirectObj = args["iobj"]
    if not item.lightable:
        output("You can't light the %s." % item.name)
        return 0
    if item.lit:
        output("The %s is already lit." % item.name)
        return 0
    if type(item.lightable) == ListType or type(item.lightable) == TupleType:
        if not indirectObj:
            output("You can't light the %s. You need something else." % item.name)
            return 0
        elif indirectObj not in item.lightable:
            output("Can't light it with that!")
            return 0
    
    item.lit = 1
    output("You lit the %s." % item.name)
    return 1

def defaultExtinguish(args):
    item = args["item"]
    if item.lightable and item.lit:
        item.lit = 0
        output("You extinguished the %s." % item.name)
        return 1
        
    else:
        output("The %s is not lit." % item.name)
        return 0 
    
    return 0

def defaultPutin(args):       
    item = args["item"]
    container = args["container"]

    item.location.inventory.remove(item)
    item.location = container
    container.inventory.append(item)
    item.location = container
    output("You just put the %s in the %s." % (item.name, container.name))
    return 1

def defaultHit(args):
    output("Who the hell do you think you are?")
    return 0
    
def defaultExamine(args):
    item = args["item"]
    output(item.printdesc())
    return 1
    
def defaultPush(args):
    item = args["item"]
    output("You have pushed the %s, nothing really happened." % item.name)
    return 0
    
def defaultPull(args):
    item = args["item"]    
    output("You have pulled the %s, nothing happened." % item.name)
    return 0
    
##### CHARACTER TRIGGERS #####

def characterExamine(args):
    character = args["character"]    
    output(character.printdesc())
    return 1